﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Bll;

namespace Runda.CMS.Portal.Shared
{
    public partial class ChangePassword : BasePage
    {
        public override bool IsCheckAccessible
        {
            get
            {
                return false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtUserName.Text = CurrentUserEntity.UserName;
                txtAccount.Text = CurrentUserEntity.Account;
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (txtNewPwd.Text.Trim() != txtConfirmPwd.Text.Trim())
            {
                ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('两次密码不一致!');", true);
                return;
            }
            SystemBll bll = new SystemBll();
            OperateResult result = bll.ChangePassword(base.CurrentUserEntity, System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtOldPwd.Text.Trim(), "MD5"), System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPwd.Text.Trim(), "MD5"));
            if (result.ErrorCode != OperateStatus.Normal)
            {
                //lblMessage.Text = result.ErrorMessage;
                ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('"+result.ErrorMessage+"!');", true);
                return;
            }
            ClientScript.RegisterStartupScript(this.GetType(), "success", "parent.window.close();", true);
        }
    }
}
